/**
 * 组件安装
 */

// 引入 gulp及组件
var gulp    = require('gulp'),                 //基础库
    cleancss = require('gulp-clean-css'),      //css压缩
    jshint = require('gulp-jshint'),           //js检查
    uglify  = require('gulp-uglify'),          //js压缩
    rename = require('gulp-rename'),           //重命名
    concat  = require('gulp-concat'),          //合并文件
    clean = require('gulp-clean');             //清空文件夹

// 样式处理
gulp.task('css', function () {

    var cssSrc = [
            './public/css/app.css'
        ],
        cssDst = './public/dist';

    gulp.src(cssSrc)
        .pipe(concat('app.css'))
        .pipe(rename({ suffix: '.min' }))
        .pipe(cleancss())
        .pipe(gulp.dest(cssDst));
});


// js处理
gulp.task('js', function () {
    var jsSrc = [
            './public/js/app.js'
        ],
        jsDst ='./public/dist';

    gulp.src(jsSrc)
        .pipe(jshint.reporter('default'))
        .pipe(concat('app.js'))
        //.pipe(gulp.dest(jsDst))
        .pipe(rename({ suffix: '.min' }))
        .pipe(uglify())
        .pipe(gulp.dest(jsDst));
});


// 清空所有 运行语句 gulp clean
gulp.task('clean', function() {
    gulp.src(['./public/dist/*'], {read: false})
        .pipe(clean());
});

// 默认任务 清空所有并重建 运行语句 gulp
gulp.task('default', ['clean'], function(){
    gulp.start('css','js');
});
